package com.ruoyi.web.controller.memberCoupon;


import java.util.List;
import javax.servlet.http.HttpServletResponse;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.TableTimeCardManagement;
import com.ruoyi.system.service.ITableTimeCardManagementService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 桌台时长卡管理，记录时长卡的基础信息、有效期、使用规则及销售配置Controller
 *
 * @author ruoyi
 * @date 2025-05-21
 */
@Api(tags="桌台时长卡管理")
@RestController
@RequestMapping("/system/tableTimeCardManagement")
public class TableTimeCardManagementController extends BaseController
{
    @Autowired
    private ITableTimeCardManagementService tableTimeCardManagementService;

    /**
     * 通过时长卡名称和状态查询桌台时长卡管理列表
     */
    @ApiOperation("查询桌台时长卡管理列表")
    @PreAuthorize("@ss.hasPermi('system:management:list')")
    @GetMapping("/list")
    public TableDataInfo list(@RequestParam(required = false) String cardName,@RequestParam(required = false) String status)
    {
        startPage();
        List<TableTimeCardManagement> list = tableTimeCardManagementService.selectTableTimeCardManagementListByConditions(cardName,status);
        return getDataTable(list);
    }

    /**
     * 导出桌台时长卡管理列表
     */
    @ApiOperation("导出桌台时长卡管理列表")
    @PreAuthorize("@ss.hasPermi('system:management:export')")
    @Log(title = "桌台时长卡管理，记录时长卡的基础信息、有效期、使用规则及销售配置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, @RequestParam(required = false) String cardName,@RequestParam(required = false) String status)
    {
        List<TableTimeCardManagement> list = tableTimeCardManagementService.selectTableTimeCardManagementListByConditions(cardName,status);
        ExcelUtil<TableTimeCardManagement> util = new ExcelUtil<TableTimeCardManagement>(TableTimeCardManagement.class);
        util.exportExcel(response, list, "桌台时长卡管理，记录时长卡的基础信息、有效期、使用规则及销售配置数据");
    }

    /**
     * 通过id获取桌台时长卡管理详细信息
     */
    @ApiOperation("通过id获取桌台时长卡管理详细信息")
    @PreAuthorize("@ss.hasPermi('system:management:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(tableTimeCardManagementService.selectTableTimeCardManagementById(id));
    }

    /**
     * 新增桌台时长卡管理
     */
    @ApiOperation("新增桌台时长卡管理")
    @PreAuthorize("@ss.hasPermi('system:management:add')")
    @Log(title = "桌台时长卡管理，记录时长卡的基础信息、有效期、使用规则及销售配置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TableTimeCardManagement tableTimeCardManagement)
    {
        return toAjax(tableTimeCardManagementService.insertTableTimeCardManagement(tableTimeCardManagement));
    }

    /**
     * 修改桌台时长卡管理
     */
    @ApiOperation("修改桌台时长卡管理")
    @PreAuthorize("@ss.hasPermi('system:management:edit')")
    @Log(title = "桌台时长卡管理，记录时长卡的基础信息、有效期、使用规则及销售配置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TableTimeCardManagement tableTimeCardManagement)
    {
        return toAjax(tableTimeCardManagementService.updateTableTimeCardManagement(tableTimeCardManagement));
    }

    /**
     * 通过id批量删除桌台时长卡管理信息
     */
    @ApiOperation("通过id批量删除桌台时长卡管理信息")
    @PreAuthorize("@ss.hasPermi('system:management:remove')")
    @Log(title = "桌台时长卡管理，记录时长卡的基础信息、有效期、使用规则及销售配置", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tableTimeCardManagementService.deleteTableTimeCardManagementByIds(ids));
    }
}
